<?php

namespace App\V3\V3_2_7\Controllers;

use App\Http\Requests\V3_2_7\ScanCodeInStorageRequest;
use App\V3\V3_2_7\Services\ScanCodeOutStorageService;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Cache;

class ScanCodeOutStorageController extends BaseController
{
    /**
     *扫码入库-孵化基地
     * Author: zlf
     * Created at 2024/6/27 15:50
     * @param ScanCodeInStorageRequest $request
     * @return JsonResponse
     */
    public function codeOutStorage(ScanCodeInStorageRequest $request): JsonResponse
    {   $data = $request->all();
        $data['time'] = time();
        $data['batch_title'] = $this->batchTitle();
        $data['main_id'] = $this->getMainUserId();
        $data['user_id'] = $this->getUserId();
        $this->operateLog('扫码出库', $data, $data['time']);
        return Cache::lock($data['type_id'] . __CLASS__ . __FUNCTION__ . $data['user_id'], 5)
            ->get(function () use ($data) {
                // 锁定 5 秒并自动释放...
                return response()->json(ScanCodeOutStorageService::scanCodeOutStorage($data));
            });
    }
}
